#ifndef __DICTIONARY_H_
#define __DICTIONARY_H_

#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using std::ifstream;
using std::map;
using std::pair;
using std::set;
using std::string;
using std::stringstream;
using std::vector;

class Dictionary {
  public:
    static Dictionary *getInstance();
    static void delInstance();

    // 方法函数
    void init(const string &dictpath);

    vector<pair<string, int>> &getEngDict();
    vector<pair<string, int>> &getChsDict();
    map<string, set<int>> &getEngIndexTable();
    map<string, set<int>> &getChsIndexTable();

    Dictionary(const Dictionary &) = delete;
    Dictionary &operator=(const Dictionary &) = delete;

  private:
    Dictionary();
    ~Dictionary();

    void loadDictionary(const string &, vector<pair<string, int>> &);
    void loadIndexTable(const string &, map<string, set<int>> &);

  private:
    vector<pair<string, int>> _eng_dict; // 字典文件
    vector<pair<string, int>> _chs_dict;
    map<string, set<int>> _eng_indexTable; // 字典索引
    map<string, set<int>> _chs_indexTable;
    static Dictionary *_instance;
};
#endif